package com.ssyc.gsk_teacher_appraisal.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseItemDraggableAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ssyc.common.utils.SPUtil;
import com.ssyc.gsk_teacher_appraisal.R;
import com.ssyc.gsk_teacher_appraisal.activity.TkTeacherAppraisalQuestionActivity;
import com.ssyc.gsk_teacher_appraisal.bean.AppraisalTestInfo;
import com.ssyc.gsk_teacher_appraisal.constant.TeacherAppKeys;

import java.util.List;

/**
 * 首页考试列表的适配器
 * Created by Kevin on 2018/10/24.
 */

public class MainTestRvAdapter extends BaseItemDraggableAdapter<AppraisalTestInfo.ListBean, BaseViewHolder> {
    private Context context;
    private String classnum;

    public MainTestRvAdapter(Context context, int layoutResId, List<AppraisalTestInfo.ListBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, AppraisalTestInfo.ListBean item) {

        //设置考试标题
        helper.setText(R.id.tv_name,  item.getRange()+item.getTag());
        //设置考试时间
        helper.setText(R.id.tv_detail_time, item.getCreate_time());

        //判断是否完成考试
        if(item.getDone_count().equals("0")){
            //无人作答
            helper.setImageDrawable(R.id.iv_set_state,context.getDrawable(R.drawable.teacher_test_nofinish));
        }else{
            //有人作答
            helper.setImageDrawable(R.id.iv_set_state,context.getDrawable(R.drawable.teacher_test_finish));
        }

        //查看详情的布局
        LinearLayout ll = helper.getView(R.id.ll_details);
        ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                // 1老师查看全校成绩(34号接口) 2老师预览试卷(32号接口)
                if(item.getDone_count().equals("0")) {
                    //预览
                    SPUtil.put(context, TeacherAppKeys.AUTHERTYPE, 2);
                }else{
                    //查看全校成绩
                    SPUtil.put(context, TeacherAppKeys.AUTHERTYPE, 1);
                }

                //保存条目的试卷名称
                SPUtil.put(context,"shareconent", item.getRange()+item.getTag());
                //跳转到查看详情的界面
                Intent intent = new Intent(context, TkTeacherAppraisalQuestionActivity.class);
                intent.putExtra("rowId", item.getRow_id2());
                intent.putExtra("exam_id", item.getExam_id());
                intent.putExtra("school_id", item.getSchool_id());
                intent.putExtra("testName", item.getTag());
                intent.putExtra("rangetag", item.getRange()+item.getTag());
                intent.putExtra("isShowMore","1");

                context.startActivity(intent);
            }
        });
    }
}
